package com.cheng.example.atguigu.view2.client17;

import com.cheng.example.atguigu.view2.User;

import java.util.concurrent.atomic.AtomicReference;

public class AtomicReferenceDemo {

    public static void main(String[] args) {
        User z3 = new User("z3", 22);
        User li4 = new User("li4", 25);
        AtomicReference<User> atomicReference = new AtomicReference<>();
        atomicReference.set(z3);

        System.out.println(atomicReference.compareAndSet(z3, li4)+"\t"+atomicReference.get());
        System.out.println(atomicReference.compareAndSet(z3, li4)+"\t"+atomicReference.get());
        User user = atomicReference.get();

        AtomicReference atomicReference1 = new AtomicReference<>(100);
        System.out.println(atomicReference1.compareAndSet(100, 101)+"\t"+atomicReference1.get());
        System.out.println(atomicReference1.compareAndSet(100, 101)+"\t"+atomicReference1.get());
    }

}
